/*
 * ResizeGridView.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.GridView;

/**
 * ListView中使用的GridView,对GridView的高度进行了重新测量,避免显示不全的情况.
 */
public class ResizeGridView extends GridView {
    private boolean mEventEnable = true;

    public ResizeGridView(Context context) {
        super(context);
    }

    public ResizeGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ResizeGridView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

    public void setTouchEventEnable() {
        mEventEnable = false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return mEventEnable ? super.onTouchEvent(ev) : mEventEnable;
    }
}
